﻿using Cxuu.Common;
using Cxuu.Models;
using Microsoft.Extensions.DependencyInjection;
using PetaPoco;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Cxuu.Repository
{
    [UseDI(ServiceLifetime.Scoped)]
    public class ArticleCateRepository : BaseRepository<ArticleCate, PetaPocoContext>
    {

        public ArticleCateRepository(PetaPocoContext petaPocoContext) : base(petaPocoContext) { }

        //获取指定数据列表
        public async Task<List<ArticleCate>> CateRoleListAsync(int[] cid)
        {
            Sql sql = Sql.Builder;
            sql.Select("*")
                .From("cxuu_article_cate")
                .Where("Id IN (@value)", new { value = cid });

            return await CreateDAO().FetchAsync<ArticleCate>(sql);
        }

        /// <summary>
        /// 获取指定栏目列表 前台
        /// </summary>
        /// <returns></returns>
        public async Task<List<ArticleCate>> CateListByIdAsync(string cid, bool type, string orderBy)
        {
            Sql sql = Sql.Builder;
            sql.Select("*")
               .From("cxuu_article_cate");

            if (cid != "0")
                sql.Where("Id IN (" + cid + ")");

            if (type)
                sql.Where("Type <> 1");

            sql.OrderBy(orderBy);

            return await CreateDAO().FetchAsync<ArticleCate>(sql);
        }
    }
}
